package com.hk.dao.manage.user.enums;

import com.hk.commons.eunms.Enums;

public enum  UserStatusEnum implements Enums<String> {
    ENABLE("enable","启用"),
    DISABLE("disable","禁用");

    private String code;
    private String desc;

    private UserStatusEnum(String code, String desc){
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    @Override
    public String getDesc(Object... objs) {
        return desc;
    }

    // 通过value获取对应的枚举对象
    public static UserStatusEnum getEnums(String value) {
        for (UserStatusEnum code : UserStatusEnum.values()) {
            if (code.getCode().equals(value)) {
                return code;
            }
        }
        return null;
    }

    /**
     * 根据 code 获得 desc
     * @param code
     * @return
     */
    public static String getValueByKey(String code) {
        UserStatusEnum[] enums = UserStatusEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if (enums[i].getCode().equals(code)) {
                return enums[i].getDesc();
            }
        }
        return "";
    }

    public static String getKeyByValue(String code) {
        UserStatusEnum[] enums = UserStatusEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if (enums[i].getDesc().equals(code)) {
                return enums[i].getCode();
            }
        }
        return "";
    }
}
